define(function(){
    class Register{
        constructor(options){
            this.user = options.ouser
            this.pass = options.opass
            this.btn = options.obtn
            this.span = options.ospan
    
            this.addEvent()
        }
        addEvent(){
            var that = this;
            this.btn.onclick = function(){
                that.setLocal()
            }
			this.user.onblur =function(){
				
			}
        }
        setLocal(){
            // 之前有没有
            this.userMsg = localStorage.getItem("userMsg");
            this.userMsg = this.userMsg ? JSON.parse(this.userMsg) : [];
    
            // 之前没有，直接存
            if(this.userMsg.length<1){
                this.userMsg.push({
                    user:this.user.value,
                    pass:this.pass.value,
                    onoff:0
                })
            }else{
                // 之前有，判断是否重名
                var o = this.userMsg.some(val=>{
                    return val.user === this.user.value;
                })
                if(o){
                    this.span.innerHTML = "用户已存在，请"+"<a href='login.html' id='reg_dl'>登录</a>";
                }else{
                    this.span.innerHTML = "";
                    this.userMsg.push({
                        user:this.user.value,
                        pass:this.pass.value,
                        onoff:0
                    })
                }
            }
    
            localStorage.setItem("userMsg",JSON.stringify(this.userMsg))
        }
    }
    
    return {
		reg1:Register
	}
	
});